package com.cositas.dulces.lp;

import java.io.IOException;
import java.util.Date;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cositas.dulces.lp.model.Product;
import com.cositas.dulces.lp.model.ShoppingCart;
import com.cositas.dulces.lp.model.ShoppingCartStatus;
import com.cositas.dulces.lp.products.Products;
import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyService;
import com.googlecode.objectify.Query;

@SuppressWarnings("serial")
public class TestServlet extends HttpServlet {
	
	@Override
	public void init(ServletConfig config) throws ServletException {
		// TODO Auto-generated method stub
		super.init(config);
		
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doService();
	}
	
	public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		doService();
	}

	public void doService() {
		
		String id = String.valueOf(System.currentTimeMillis());
		ShoppingCart sh = ApplicationFacade.getOpenShoppingCart(id);
		ApplicationFacade.addProduct(id, new Product(Products.TARTA_FRUTILLA, 1, ""));
		
		System.out.println(ApplicationFacade.getOpenShoppingCart(id));
		System.out.println(ApplicationFacade.addProduct(id, new Product(Products.TARTA_FRUTILLA, 1, "")));
		System.out.println(ApplicationFacade.addProduct(id, new Product(Products.TARTA_COCO, 2, "")));
		ApplicationFacade.placeOrder(id, "email", "phone", "address", new Date());
		System.out.println(ApplicationFacade.getShoppingCart(sh.id));
		
		System.out.println(ApplicationFacade.addProduct(id, new Product(Products.TARTA_FRUTILLA, 1, "")));
		System.out.println(ApplicationFacade.addProduct(id, new Product(Products.PASTAFROLA_MEM, 1, "")));
		ApplicationFacade.requestBudget(id, "email", "phone", "address", new Date());
		sh = ApplicationFacade.getOpenShoppingCart(id);
		System.out.println(ApplicationFacade.getShoppingCart(sh.id));
		
		System.out.println(ApplicationFacade.getOpenShoppingCart(id));
	}
}
